﻿@{
    Layout = "~/Views/Shared/_Main.cshtml";
}
@using SRF.UI.Html
@section header{
    <style type="text/css">
        .leftpanel
        {
            float: left;
            width: 200px;
        }
        .leftpanel select
        {
            width: 100%;
            overflow: hidden;
        }
        .rightpanel
        {
            margin-left: 210px;
        }
    </style>
    <script src="@Url.Content("~/Scripts/jquery-ui/js/jquery.ui.core.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery-ui/js/jquery.ui.widget.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery-ui/js/jquery.ui.mouse.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery-ui/js/jquery.ui.draggable.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/bootstrap/js/bootstrap-modal.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.cookie.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/dialog.js")" type="text/javascript"></script> 
    <script type="text/javascript" language="javascript">
        var curDictId; //当前选中的数据规则
        var curDictKey = "DataRulelist_curDictId"; //当前选中的数据规则id保存在cookie的key
        $(function () {
            $("select").removeAttr("multiple"); //不让列表多选  
            $("#DataRuleList").on("change", function () {
                if ($(this).val() != null && $(this).val() != curDictId) {
                    curDictId = $(this).val();
                    loadDataRuleItem();
                }
            }).on("dblclick", function () {
                var action = $("#DataRuleList").val() ? "update" : "add";
                openEditor(action);
            });
            //默认选中数据规则
            curDictId = $.cookie(curDictKey);
            if (curDictId == null) {
                curDictId = $("#DataRuleList>option:eq(0)").val();
            }
            if (curDictId != null) {
                $("#DataRuleList").val(curDictId);
                loadDataRuleItem();
            }
        })

        function loadDataRuleItem() {
            var url = buildUrl("ItemList", { DataRuleid: curDictId }, true);
            $("#DataRuleItemList").iframeLoading(url, { left: 180 });
            $.cookie(curDictKey, curDictId);
            $(".leftpanel :button").removeAttr("disabled");
        }
        function openEditor(action) {
            switch (action) {
                case "add":
                    {
                        url = "edit";
                        title = "新增数据规则";
                    }
                    break;
                case "update":
                    {
                        var params = {};
                        params.id = $("#DataRuleList").val();
                        url = "Edit?" + $.param(params);
                        title = "修改数据规则";
                    }
                    break; 
            }
            //新增\修改
            $.dialog({
                url: url,
                title: title,
                height: 300,
                width: 500,
                callback: function (returnValue) { 
                    location.reload();
                },
                loading: function () {
                    $(this).iframeLoading();
                }
            });
        }
        function deleteDataRule() {
            $.confirm("您确定要删除该数据规则吗？", "确认删除", function (returnValue) {
                if (returnValue == "ok") {
                    var url = Global.contextPath + "/admin/DataRule/delete";
                    $.get(url, { id: curDictId }, function (data) {
                        if (data) {  //发生异常
                            alert(data);
                        }
                        else {
                            $.cookie(curDictKey, null);
                            location.reload();
                        }
                    });
                };
            });
        }
    </script>
}
@section toolbar
{ 
}
<div>
    <div class="leftpanel">
        @Html.ListBox("DataRuleList", ViewBag.DataRuleList as IEnumerable<SelectListItem>, new { size = "25" })
        <input type="button" class="btn btn-primary btn-small" value="新增" onclick="openEditor('add');" />
        <input type="button" class="btn btn-primary btn-small" value="修改" onclick="openEditor('update');"
            disabled="disabled" />
        <input type="button" class="btn btn-primary btn-small" value="删除" onclick="deleteDataRule();"
            disabled="disabled" />
    </div>
    <div class="rightpanel">
        <iframe id="DataRuleItemList" src="" width="800" height="450" frameborder="0" style="margin-left: 15px">
        </iframe>
    </div>
</div>
